﻿using AutoMapper;
using MediatR;
using S.Breeding.Api.Application.Command.BodyMeasureCommand;
using S.Breeding.Domain;
using S.Breeding.Infrastructure;

namespace S.Breeding.Api.Application.CommandHandlers.BodyMeasureCommandHandlers
{
    public class BodyMeasureCreateCommandHandlers : IRequestHandler<BodyMeasureCreateCommand, int>
    {
        private readonly IRepository<BodyMeasure> repository;
        private readonly IMapper mapper;
        public BodyMeasureCreateCommandHandlers(IRepository<BodyMeasure> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(BodyMeasureCreateCommand request, CancellationToken cancellationToken)
        {
            return await repository.CreateAsync(mapper.Map<BodyMeasure>(request));
        }
    }
}
